import React, { MutableRefObject, RefObject } from 'react';
import { ConditionsType, PageInfo, TableCtxType, TablePreviewProps } from './interfaces';
import { inbiz as IPageInbiz } from '@inbiz/render';
import { OrderInfo } from '@inbiz/hooks';

interface InBizTableCtxProps extends TablePreviewProps { }

export interface SearchParamsProps {
  pageInfo: PageInfo;
  conditions?: ConditionsType[];
  orders?: OrderInfo[];
}

export interface InBizTableRefCtxProps {
  searchRef: MutableRefObject<SearchParamsProps>;
  eventsRef: MutableRefObject<any>;
  firstRequestRef: MutableRefObject<boolean>;
  pageRef: RefObject<{ page: IPageInbiz }>;
}

export const InBizTableCtx = React.createContext<InBizTableCtxProps>({});
export const InBizTableRefCtx = React.createContext<InBizTableRefCtxProps>({
  searchRef: {
    current: {
      pageInfo: { current: 1, pageSize: 30 },
    },
  },
  eventsRef: { current: null },
  firstRequestRef: { current: true },
  pageRef: { current: { page: {} as IPageInbiz } },
});
export const TableCtx = React.createContext<TableCtxType>({
  modelKey: '',
  sourceModel: '',
  refresh: () => { },
  handlePrint: () => { },
  tableCacheRef: { current: null },
});
